#!/usr/bin/python3
import os, shutil, sys

"""
解散指定文件夹，文件名重复将直接覆盖，请谨慎操作
"""
dirs = ['']

try:
    for dir in dirs:
        if not os.path.exists(dir):
            print(f'{dir} is not exists.')
            continue
        for root, _, files in os.walk(dir):  # 遍历目标文件夹，移动文件
            for f in files:
                filePath = os.path.join(root,f)
                rootPath = os.path.join(dir, os.path.basename(f))
                if os.path.exists(rootPath):
                    os.remove(rootPath)
                    print(f'Rewrite same name file: {rootPath}')
                shutil.move(filePath, dir)
        for f in os.listdir(dir):  # 删除空文件夹
            dirPath = os.path.join(dir, f)
            if os.path.isdir(dirPath):
                shutil.rmtree(dirPath)
except Exception as e:
    print(f'Error: {e}')
print('Unpack "{}" finished'.format(dir))